<html>
 <head>
  <meta charset="UTF-8">
 </head>
 <body>
  <h1 data-lake-id="hHS7X" id="hHS7X"><span data-lake-id="uee9df2fa" id="uee9df2fa">典型回答</span></h1>
  <p data-lake-id="u206deb9b" id="u206deb9b"><br></p>
  <p data-lake-id="u2fb484a2" id="u2fb484a2"><span data-lake-id="u5fc19dbe" id="u5fc19dbe">DDD的分层架构是一个四层架构，从上到下依次是：用户接口层、应用层、领域层和基础层。</span></p>
  <p data-lake-id="uaa207a3b" id="uaa207a3b"><span data-lake-id="u2453bbac" id="u2453bbac">​</span><br></p>
  <p data-lake-id="u89ebf279" id="u89ebf279"><img src="https://cdn.nlark.com/yuque/0/2023/png/5378072/1685861039102-25f6a7a4-2c2a-4f05-a775-99079935332e.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_32%2Ctext_SmF2YSA4IEd1IFA%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10"></p>
  <p data-lake-id="ub7deaebf" id="ub7deaebf"><br></p>
  <p data-lake-id="u27a7534e" id="u27a7534e"><span data-lake-id="u45851eb9" id="u45851eb9">层次之间的调用关系是上层可以调用下层，即用户接口层可以调用应用层、领域层及基础层。应用层可以调用领域层和基础层，领域层可以调用基础层。</span></p>
  <p data-lake-id="ua984f050" id="ua984f050"><span data-lake-id="u6c9d6fdc" id="u6c9d6fdc">​</span><br></p>
  <p data-lake-id="u779c3e42" id="u779c3e42"><span data-lake-id="u3c33d899" id="u3c33d899">但是不能从下往上反向调用，各个层级之间是严格的单向调用的依赖关系。</span></p>
  <p data-lake-id="uaeb15faf" id="uaeb15faf"><br></p>
  <p data-lake-id="u5f9c1155" id="u5f9c1155"><span data-lake-id="u684dd28d" id="u684dd28d">除了这种简单的四层架构以外，DDD中还有比较典型的洋葱架构和六边形架构</span></p>
  <p data-lake-id="u347aaa22" id="u347aaa22"><span data-lake-id="u41ba18da" id="u41ba18da">​</span><br></p>
  <p data-lake-id="u5c51bad2" id="u5c51bad2"><span data-lake-id="ub13ba4a6" id="ub13ba4a6">洋葱架构，就是像洋葱一样的一层一层，从外到内的架构形式，如下图：</span></p>
  <p data-lake-id="ubf7d1d72" id="ubf7d1d72"><span data-lake-id="u8321344a" id="u8321344a">​</span><br></p>
  <p data-lake-id="ud0317b4e" id="ud0317b4e"><img src="https://cdn.nlark.com/yuque/0/2023/png/5378072/1685861299754-4524e227-7f8d-4f7f-b466-2d20fdea61a1.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_32%2Ctext_SmF2YSA4IEd1IFA%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10"></p>
  <p data-lake-id="u2c56131e" id="u2c56131e"><br></p>
  <p data-lake-id="uf132eba3" id="uf132eba3"><span data-lake-id="u1fe7966a" id="u1fe7966a">他的依赖关系是从外到内的。</span></p>
  <p data-lake-id="ue9eaedd5" id="ue9eaedd5"><span data-lake-id="ucdbef7a8" id="ucdbef7a8">​</span><br></p>
  <p data-lake-id="u7b8de86c" id="u7b8de86c"><span data-lake-id="u05943872" id="u05943872">六边形架构和洋葱架构有点像，只不过不是圆形，而是六边形的：</span></p>
  <p data-lake-id="ue42d59d4" id="ue42d59d4"><span data-lake-id="u5c0cbb63" id="u5c0cbb63">​</span><br></p>
  <p data-lake-id="u2e08738d" id="u2e08738d"><img src="https://cdn.nlark.com/yuque/0/2023/png/5378072/1685861346529-f22178f9-944f-4b3b-a9c3-4fc2ed9577ea.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_33%2Ctext_SmF2YSA4IEd1IFA%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10"></p>
  <p data-lake-id="u91fa8552" id="u91fa8552"><br></p>
  <p data-lake-id="ubeb445d2" id="ubeb445d2"><span data-lake-id="u3e137a2a" id="u3e137a2a">虽然 DDD 分层架构、整洁架构、六边形架构的架构模型表现形式不一样，但是这三种架构模型的设计思想都是微服务架构高内聚低耦合原则的完美体现，</span><strong><span data-lake-id="ucfeb3439" id="ucfeb3439">都是以领域模型为中心的设计思想</span></strong><span data-lake-id="u07259590" id="u07259590">。</span></p>
  <p data-lake-id="u8f31cd68" id="u8f31cd68"><span data-lake-id="uebbb7cf3" id="uebbb7cf3">​</span><br></p>
  <p data-lake-id="ue0d4dd97" id="ue0d4dd97"><img src="https://cdn.nlark.com/yuque/0/2023/png/5378072/1685861394105-ef041ab6-8d33-416b-9617-44a263ef1d62.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_37%2Ctext_SmF2YSA4IEd1IFA%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10"></p>
  <p data-lake-id="u66f0fb79" id="u66f0fb79"><br></p>
  <p data-lake-id="u614898bc" id="u614898bc"><br></p>
  <p data-lake-id="u319fc219" id="u319fc219"><span data-lake-id="u5f05124a" id="u5f05124a">本文图片参考自：《极客时间——DDD实战课》</span></p>
 </body>
</html>